﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace Our.Umbraco.DataType.Bitly
{
	/// <summary>
	/// The options for the bit.ly data-type.
	/// </summary>
	public class BitlyOptions
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="BitlyOptions"/> class.
		/// </summary>
		public BitlyOptions()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="BitlyOptions"/> class.
		/// </summary>
		/// <param name="loadDefaults">if set to <c>true</c> [load defaults].</param>
		public BitlyOptions(bool loadDefaults)
		{
			if (loadDefaults)
			{
				// get the type of the object.
				var type = this.GetType();

				// iterate through the properties.
				foreach (var property in type.GetProperties())
				{
					// iterate through the DefaultValue attributes.
					foreach (DefaultValueAttribute attribute in property.GetCustomAttributes(typeof(DefaultValueAttribute), true))
					{
						// set the default value of the property.
						property.SetValue(this, attribute.Value, null);
					}
				}
			}
		}

		/// <summary>
		/// Gets or sets the bit.ly username.
		/// </summary>
		/// <value>The bit.ly username.</value>
		[DefaultValue("bitlyapidemo")]
		public string BitlyUsername { get; set; }

		/// <summary>
		/// Gets or sets the bit.ly API key.
		/// </summary>
		/// <value>The bit.ly API key.</value>
		[DefaultValue("R_0da49e0a9118ff35f52f629d2d71bf07")]
		public string BitlyApiKey { get; set; }

		/// <summary>
		/// Gets or sets a value indicating whether [auto generate].
		/// </summary>
		/// <value><c>true</c> if [auto generate]; otherwise, <c>false</c>.</value>
		[DefaultValue(false)]
		public bool AutoGenerate { get; set; }
	}
}